package com.training1.core.modules.service;


import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.training1.core.common.service.CrudService;
import com.training1.core.common.utils.DateUtils;
import com.training1.core.common.utils.excel.ExcelUtil;
import com.training1.core.entity.CompanyNameEntity;


import com.training1.core.entity.TodayMoneyEntity;
import com.training1.core.modules.dao.CompanyDao;


@Service
@Transactional
public class CompanyService extends CrudService<CompanyDao,CompanyNameEntity>{

	@Resource
	private CompanyDao companyDao;
	
	public List<CompanyNameEntity> find(){
		return companyDao.find();
	}
	
	public List<CompanyNameEntity> findAllCompanyName(){
		return companyDao.findAllCompanyName();
	}
	
	public List<TodayMoneyEntity> findAll(){
		return companyDao.findAll();
	}
	
	public List<TodayMoneyEntity> findLike(TodayMoneyEntity TodayMoney){
		return companyDao.findLike(TodayMoney);
	}
	
	public void export(HttpServletResponse response,TodayMoneyEntity TodayMoney){
		List<TodayMoneyEntity> cqList=companyDao.export(TodayMoney);
		//设置列标题
		List<String> excelHead = new ArrayList<String>();
		excelHead.add("合同编号");
		excelHead.add("用户姓名");
		excelHead.add("所属公司");
		excelHead.add("联系电话");
		excelHead.add("拟借金额");
		excelHead.add("申请日期");
		excelHead.add("服务期数");
		//设置内容
		List<List<String>> dataList = new ArrayList<List<String>>();
		for(TodayMoneyEntity cq : cqList){
			List<String> data = new ArrayList<String>();
			data.add(cq.getId()+"");
			data.add(cq.getCustomerName());
			data.add(cq.getOrgName());
			data.add(cq.getCustomerPhone());
			data.add(cq.getExoAmount()+"");
			data.add(cq.getAppDateStr());
			data.add(cq.getApprovalCyc()+"");
			dataList.add(data);
		}
		//设置文件名
		String fileName;
		String sheetName = "sheet1";
		String titleName;
		fileName = "今日应收表_"+DateUtils.getDate().replace("-", "");
		titleName = "今日应收表_"+DateUtils.getDate().replace("-", "");
		
		ExcelUtil.exportExcel(response, excelHead, dataList, fileName, sheetName,titleName);
	}

}
